package com.gamecauca.common;

import java.io.Serializable;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;
import com.gamecauca.Input;
import com.gamecauca.common.Colliders;
import com.gamecauca.common.CollisionGeometry;
public class GameObject  implements Serializable{
	public Vector2 position = new Vector2();;
	public final Rectangle bounds;
	private Vector3 touchPoint;
	
	//begin Kiem thanh thienloccse@gmail.com
	// nhung thuoc tinh ,function chung nhat
	// duoc dat o day 
	public int kindOfObject;// doi tuong nay la gi??
    public boolean Visible;
    public float  x_Speed;//van toc di chuyen theo huong X
    public float  y_Speed;// van toc di chuyen theo huong y

    public int direction;// huong di chuyen
    public int sideAppear;// huong xuat hien ban dau 
    public int iTimer;
    
    protected float weight;//trong luong cua doi tuong
    protected int price;//gia ban trong market
    protected int moneyValue;//gia tri cua ca
    protected int blood; //mau cua doi tuong
    protected int effectValue; //gia tri hieu ung
    protected int effectTime; //thoi gian tuong tac hieu ung
	
    public int iCounterToEraseResetDirectFlag;
    public boolean isReset;
//    public boolean isCapture;// neu bi bat giu thi bat co len
    public boolean isCaptureFinished;// neu bi bat giu ket thuc thi bat co len
	//end 
//    public boolean isCreate = false;// khi dua vao array thi bat co len

	
	//=========================================
	/** The default state for any new game object. */
	public static final int INACTIVE = -1;

	/** This game object's x coordinate in world space. */
//	public float x;

	/** This game object's y coordinate in world space. */
//	public float y;

	/** This game object's width in world units. */
	public float width;

	/** This game object's height in world units. */
	public float height;

	/** This game object's collision geometry (if it has any) in local coordinates. */
	public CollisionGeometry geometry;

	/** This game object's current state. */
//	public int state;

	/** How long this game object has been in its current state (in seconds). */
	public float stateTime;

	/** Will be true if this game object is in collision. */
	public boolean inCollision;

	// Holds this game object's bounding rectangle in world space.

	public GameObject() {
		stateTime = 0.0f;
		inCollision = false;
		bounds = new Rectangle();
		touchPoint = new Vector3();
	}
	
	public GameObject (float x, float y, float width, float height) {
		this.position = new Vector2(x, y);
		this.bounds = new Rectangle(x - width / 2, y - height / 2, width, height);
//		this.bounds = new Rectangle(x , y , width, height);
		touchPoint = new Vector3();
	}
	
//	public GameObject (float x, float y,TextureRegion region) {
//		this.position = new Vector2(x, y);
//		this.bounds = new Rectangle(x - region.getRegionWidth() / 2, y - region.getRegionHeight() / 2, region.getRegionWidth(), region.getRegionWidth());
//		touchPoint = new Vector3();
//	}

	/** Assigns collision geometry to this <code>GameObject</code>.
	 * @param geometry the new collision geometry. */
	public void setGeometry (CollisionGeometry geometry) {
		this.geometry = geometry;
	}

	/** Returns this <code>GameObject</code>'s bounding rectangle.
	 * @return the bounding rectangle. */
	public Rectangle bounds () {
		bounds.x = position.x;
		bounds.y = position.y;
		bounds.width = width;
		bounds.height = height;
		return bounds;
	}

	/** Switches this game object into a new state and resets {@link stateTime}.
	 * @param state the new state. */
//	public void setState (int state) {
//		this.state = state;
//		stateTime = 0.0f;
//	}

	/** Returns true if this game object's bounds intersect with the given rectangle.
	 * 
	 * @param r the rectangle to intersect.
	 * @return true if the bounds intersect. */
	public boolean boundsIntersect (Rectangle r) {
		return Colliders.intersects(bounds(), r);
	}

	/** Returns true if this game object's bounds intersect with the given game object.
	 * 
	 * @param go the other game object.
	 * @return true if the bounds intersect. */
	public boolean boundsIntersect (GameObject go) {
		return Colliders.intersects(bounds(), go.bounds());
	}

	/** Returns true if this game object's collision geometry intersects with the given rectangle.
	 * 
	 * @param r the rectangle to intersect.
	 * @return true if the geometry intersects with the rectangle. */
	public boolean geometryIntersects (Rectangle r) {
		return geometry.intersects(r, position.x, position.y);
	}

	/** Returns true if this game object's collision geometry intersects with another game object's collision geometry.
	 * 
	 * @param go the other game object.
	 * @return true if the geometries intersect. */
	public boolean geometryIntersects (GameObject go) {
		return geometry.intersects(position.x, position.y, go.geometry, go.position.x, go.position.y);
	}

	/** Returns true if this game object is in collision with a rectangle. It first does a simple box test against this game
	 * object's bounds, then, if that's true, tests its collision geometry against the rectangle.
	 * 
	 * @param r the rectangle to intersect.
	 * @return true if this game object intersects the rectangle. */
	public boolean intersects (Rectangle r) {
		return boundsIntersect(r) && (geometry == null || geometryIntersects(r));
	}

	/** Returns true if this game object is in collision with another game object. It first does a bounds test, then, if that's
	 * true, tests its collision geometry against the other game object's collision geometry. */
	public boolean intersects (GameObject go) {
		if (!boundsIntersect(go)) {
			return false;
		}
		if (geometry == null) {
			return go.geometry == null || go.geometryIntersects(bounds());
		} else if (go.geometry == null) {
			return geometryIntersects(go.bounds());
		}
		return geometryIntersects(go);
	}

	/** Updates this game object. Typically you would override this to create interesting behaviour.
	 * 
	 * @param delta time in seconds since the last update. */
	public void update (Input input) {
	}
	//==========================================
	public void Eat(){
		
	};//tinh nang ca an ca
	public void resetDirection(){
		
	};
	public int getCoin(){
		return 0;
	};
	public void update(){
		
	};// moi doi tuong khac nhau se co ham update khac nhau
	public void render(SpriteBatch batch){
		
	};
	public  boolean checkCollision(){
		return true;
	}
	
	public float getWeight(){
		return weight;
	}
	public int getValue(){
		return moneyValue;
	}
	public int getPrice(){
		return price;
	}
	public int getBlood(){
		return blood;
	}
}